package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/10/23 7:34 PM
 * @description：https://leetcode.cn/problems/merge-strings-alternately/
 */
public class 交替合并字符串 {
    @Test
    public void test() {

    }

    class Solution {
        public String mergeAlternately(String word1, String word2) {
            int len1 = word1.length();
            int len2 = word2.length();
            StringBuilder builder = new StringBuilder(len1 + len2);
            int i = 0;
            int j = 0;
            while (i < len1 && j < len2) {
                builder.append(word1.charAt(i++));
                builder.append(word2.charAt(j++));
            }
            builder.append(word1.substring(i));
            builder.append(word2.substring(j));
            return builder.toString();
        }
    }
}
